<?php
	class CommentModel extends Model{
		public $page;		//分页的页号(当前页)
		public $evelpage=5;	//每页显示两条记录。
		public $pagenum;	//总共的页数
		public $bplist;		//输出到模版的每条记录的数据
		public $pagefor;	//显示10个页号标签
		public $count;		//总记录数
		public $logid;
		public function __construct($page,$logid){
			$this->page = $page;
			$this->logid = $logid;
			$this->pagelist();
			$this->pagefor = $this->getpagefor();
		}
		

		//获取全部评论
		public function getCommentList(){
			$list = M()->query("SELECT b.Id,b.Content,b.LogId,b.CreateUser,b.CreateDate,b.OrgName,u.UserId,u.TrueName,u.Avatar FROM blogcomment b,users u WHERE b.LogId={$this->logid} AND b.CreateUser=u.UserId ORDER BY b.Id DESC");
			return $list;
		}
		
		//获取分页列表
		public function pageList(){
			$page = $this->page;		//当前页号
			$pinfo = $this->getCommentList();
			$count = count($pinfo);		//总记录数
			$this->count = $count;
			$page=($page<1)?1:(($page>ceil($count/$this->evelpage))?ceil($count/$this->evelpage):$page);
			$t=(($page-1)*($this->evelpage));
			for($i=0;$i<($this->evelpage);$i++){
				if($pinfo[$t+$i])
					$log[$i]=$pinfo[$t+$i];
			}
			$this->bplist = $log;
			$this->pagenum = ceil($count/$this->evelpage);
		}
		
		//判断分页数受否超出
		public function getpagefor(){
			//区间
			$st=floor(($this->page)/10)*10;
			for($i=$st+1;$i<=$st+10;$i++){
				if($i>$this->pagenum){
					continue;
				}
				$lnum[]=$i;
			}
			return $lnum;
		}
		
	}
?>